#ifndef CATKIN_WS_DEMO1_H
#define CATKIN_WS_DEMO1_H

#include "bits/stdc++.h"
#include <cv_bridge/cv_bridge.h>
#include <opencv2/opencv.hpp>
#include <ros/ros.h>
#include <sensor_msgs/Image.h>
#include <serial/serial.h>
#include <signal.h>
#include <unistd.h>

#include "Line.h"

using namespace std;
using namespace cv;

#define INF        10000
#define STRIGHT    0
#define LEFT       1
#define RIGHT      2
#define DAYOUZHUAN 3
#define STR_RIGHT  4
#define BIZHANG    6
#define DAOCHE     9
#define END        10

#define IMG_SHOW  0
#define IMG_WRITE 0

#define N_CHANGE_STIM 0
#define Y_CHANGE_STIM 1
#define PREDICT_STIM  2

#define GREEN_LIGHT 1
#define RED_LIGHT   0

class TraceLine
{
    vector<vector<pair<int, int>>> T;
    Mat                            img_resize{};
    int                            left_sum;
    int                            cnt;
    int                            left_sign;

public:
    queue<int> q;
    int        stim{}, state{};
    fstream    f;

public:
    TraceLine();

    explicit TraceLine(const vector<int>& q1);

    char line_loop(Mat& img_rec, serial::Serial& ser);

public:
    Line           calculate_blue(Mat& img);
    pair<int, int> calculate_k(Mat img);
    vector<int>    calculate_predict();
    char           strategy_blue(Line& line);
    char           strategy_k(int left, int right, serial::Serial& ser);
    char           strategy_predict(vector<int>& N);
    pair<int, int> calculate_short_blue(Mat& img);
    char           strategy_short_blue(pair<int, int> p, serial::Serial& ser);
    void           read_src();
};

#endif   // CATKIN_WS_DEMO1_H
